# Contributer: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=slim
pkgver=1.4.0
pkgrel=0
pkgdesc="Desktop-independent graphical login manager for X11"
url="https://sourceforge.net/projects/slim-fork"
arch="all"
license="GPL-2.0-or-later"
options="!check"
subpackages="$pkgname-doc $pkgname-openrc"
makedepends="libxmu-dev libpng-dev libjpeg-turbo-dev libxft-dev
	cmake libxrandr-dev samurai"
depends="dbus"
source="https://downloads.sourceforge.net/project/slim-fork/slim-$pkgver.tar.gz
	https://dev.alpinelinux.org/~clandmeter/sources/slim-alpinelinux-0.2.0.tar.gz
	$pkgname.logrotate
	$pkgname.initd
	"

prepare() {
	default_prepare
	sed -i -e 's|#xserver_arguments.*|xserver_arguments   -nolisten tcp vt07|'\
		-e 's|/var/run/slim.lock|/var/lock/slim.lock|' \
		-e 's|halt_cmd.*|halt_cmd            /sbin/poweroff|'\
		-e 's|reboot_cmd.*|reboot_cmd          /sbin/reboot|'\
		-e 's|console_cmd.*|console_cmd         /usr/bin/terminal|'\
		-e 's|login_cmd.*|login_cmd           exec /bin/sh -l /etc/X11/xinit/xinitrc|' \
		-e 's|screenshot_cmd.*|screenshot_cmd      scrot /slim.png|' \
		-e 's|imagemagick|scrot|' \
		-e 's|current_theme.*|current_theme       alpinelinux|' \
		slim.conf
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_SKIP_RPATH=ON \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DUSE_PAM=no \
		-DUSE_CONSOLEKIT=no

	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -D -m755 ../slim.initd "$pkgdir"/etc/init.d/slim
	install -D -m644 ../slim.logrotate "$pkgdir"/etc/logrotate.d/slim

	# remove unused systemd service
	rm -rf "$pkgdir"/lib/systemd

	# install our default theme
	cd "$srcdir"/slim-alpinelinux
	install -d "$pkgdir"/usr/share/slim/themes/alpinelinux
	cp background.png panel.png slim.theme \
		"$pkgdir"/usr/share/slim/themes/alpinelinux/
	rm -rf "$pkgdir"/usr/share/slim/themes/default
	rm -rf "$pkgdir"/usr/share/slim/themes/original
}

sha512sums="
2ef38d39e2d5186f9342161d99740b0c8cd87f234deaf550ca1528c9a61c052d26123c7da26f4a0a5e658d01cb200b115cf7879d349ed51a6e8c729ee3fdf77f  slim-1.4.0.tar.gz
3cd3de67e5b1e122da05e02e0e6e8fe2c5a1ae07487e51068aa56ddf05d17854562350ef47c914a2c9fb2534b8f757a326cfed64f4b5ddbbeb18e48af43b46c6  slim-alpinelinux-0.2.0.tar.gz
e5f398ea58adbedea7ae40c7a907d2f926148ee6f3c51fc5761b84d1d119c091fa0cf34f908cd49300fcddea71c5c9b6f2ac21731808ce5d73ea65a65b19a55b  slim.logrotate
042803894dbc34351f2efd436b1e07610f63feb12f31d5d0cc1dc26e758d208790ff79ef678854d3ffd781776bc84033d9b752757944474e721e679d3cbcfbce  slim.initd
"
